package synchro;

/**
 *
 * @author boomar
 */
public class Race {

    static double val = 0.0;
    SemBinaire s = new SemBinaire();

    public class ThreadPlus extends Thread {

        @Override
        public void run() {
            for (int i = 0; i < 1000000; i++) {
                s.P();
                val += 1.0;
                s.V();
            }//end for
        }//end run()
    }//end ThreadPlus

    public class ThreadMoins extends Thread {

        @Override
        public void run() {
            for (int i = 0; i < 1000000; i++) {
                s.P();
                val -= 1.0;
                s.V();
            }//end for
        }//end run()
    }//end ThreadMoins

    public void go() throws InterruptedException {
        ThreadPlus Tp = new ThreadPlus();
        ThreadMoins Tm = new ThreadMoins();

        Tp.start();
        Tm.start();

        Tp.join();
        Tm.join();

        System.out.println(val);
    }//end go()

    public static void main(String[] args) throws InterruptedException {
        Race r = new Race();
        r.go();
    }//end main()
}//end Race
